<template>
  <div class="h-full bg-[rgb(48, 65, 86)]">
    <el-menu active-text-color="#ffd04b" background-color="#304156" class="el-menu-vertical-demo h-full"
      :default-active="index" text-color="#fff" @open="handleOpen" @close="handleClose" router>
      <!-- <el-sub-menu index="/firstPage">
        <template #title>
            
          <span>首页</span>
        </template>
      </el-sub-menu> -->
      <!-- <el-sub-menu > -->
        <el-menu-item index="/first">
          <el-icon>
            <Menu />
          </el-icon>
        <template #title>
          <span>首页</span>
        </template></el-menu-item>
      <!-- </el-sub-menu> -->

      <el-sub-menu index="">
        <template #title>
          <el-icon>
            <Histogram />
          </el-icon>
          <span>商品管理</span>
        </template>
        <el-menu-item index="/home/shopList">
          <template #title>
            <span>商品列表</span>
          </template></el-menu-item>

        <el-menu-item index="/home/shelves">
          <template #title>
            <span>商品上架</span>
          </template></el-menu-item>

        <el-menu-item index="/home/comments">
          <template #title>
            <span>商品评论</span>
          </template></el-menu-item>

      </el-sub-menu>

    </el-menu>
  </div>
</template>

<script setup>
import { watch, ref } from 'vue'
import { useRoute } from 'vue-router';
import { Menu, Histogram } from "@element-plus/icons-vue";
const route = useRoute()

const handleOpen = (key, keyPath) => {
  console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  console.log(key, keyPath);
};

let index = ref('/firstPage')

//监视路由变化
watch(route, (to) => {
  index.value = to.path
}, { immediate: true })
</script>

<style></style>